package com.sem.sentinel.demo01;

import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class SentinelDemo01Main {
    public static void main(String[] args) {
        SpringApplication.run(SentinelDemo01Main.class,args);
        //设置一个FlowRule流控规则 绑定sayHi资源 限制QPS上限1(测试使用)
        List<FlowRule> rules=new ArrayList<>();
        //定义当前案例的规则
        FlowRule qpsRule=new FlowRule();
        //1.qpsRule绑定资源sayHi
        qpsRule.setResource("sayHi");
        //2.限流类型 和sentinel计算方法有关,统计的数据有关 QPS 限流 并发
        qpsRule.setGrade(1);//0 并发限流 1 表示QPS限流
        //3.上限阈值 超过阈值的时候,请求就被拒绝了
        qpsRule.setCount(1);
        rules.add(qpsRule);
        //sentinel需要加载这个规则
        FlowRuleManager.loadRules(rules);
    }
}
